//
//  YD3rdInfoProfileTableViewCell.m
//  IngCard
//
//  Created by kf on 2017/8/28.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YD3rdInfoProfileTableViewCell.h"


@implementation YD3rdInfoProfileCellDataSource

-(Class) viewClass
{
    return [YD3rdInfoProfileTableViewCell class];
}

@end

@interface YD3rdInfoProfileTableViewCell()
@property(nonatomic, strong) UILabel *guideLabel;
@property(nonatomic, strong) UIImageView *headerImageView;
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *jobLable;

@property(nonatomic, strong) UIImageView *emailImageView;
@property(nonatomic, strong) UILabel *emailLabel;

@property(nonatomic, strong) UIImageView *locationImageView;
@property(nonatomic, strong) UILabel *locationLabel;

@end

@implementation YD3rdInfoProfileTableViewCell

+(CGFloat)viewHeight:(YD3rdInfoProfileCellDataSource *) dataSource
{
    return dataSource.height ?: 265;
}


- (void) initSubviews
{
    [super initSubviews];
    
    [self.contentView addSubview:self.guideLabel];
    [self.guideLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(12);
    }];
    
    [self.contentView addSubview:self.headerImageView];
    [self.headerImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.guideLabel.mas_bottom).offset(12);
        make.height.equalTo(90);
        make.width.equalTo(90);
    }];
    
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.headerImageView.mas_bottom).offset(9);
    }];
    
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(9);
    }];
    
    [self.contentView addSubview:self.jobLable];
    [self.jobLable makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(3);
    }];
    
    [self.contentView addSubview:self.emailImageView];
    [self.emailImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.jobLable.mas_bottom).offset(5);
        make.right.equalTo(self.headerImageView.mas_left).offset(-2);
    }];
    
    [self.contentView addSubview:self.emailLabel];
    [self.emailLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.emailImageView.mas_right).offset(7);
        make.centerY.equalTo(self.emailImageView);
    }];
    
    [self.contentView addSubview:self.locationImageView];
    [self.locationImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.emailImageView);
        make.top.equalTo(self.emailImageView.mas_bottom).offset(5);
    }];
    
    [self.contentView addSubview:self.locationLabel];
    [self.locationLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.locationImageView);
        make.left.equalTo(self.emailLabel);
    }];
}

-(void) onViewModelChanged
{
    YD3rdInfoProfileCellDataSource *dataSource = (YD3rdInfoProfileCellDataSource *)self.dataSource;
    if (dataSource)
    {
        self.nameLabel.text = dataSource.name;
        [self.nameLabel sizeToFit];
        
        self.titleLabel.text = dataSource.title;
        [self.titleLabel sizeToFit];
        
        self.jobLable.text = dataSource.job;
        [self.jobLable sizeToFit];
        
        self.emailLabel.text = dataSource.email;
        [self.emailLabel sizeToFit];
        
        self.locationLabel.text = dataSource.location;
        [self.locationLabel sizeToFit];
        
        UIImageViewSetUrl(self.headerImageView, dataSource.headerImageUrl);
    }
}

#pragma mark - Lazy loading

-(UILabel *)guideLabel
{
    if (!_guideLabel)
    {
        _guideLabel = [[UILabel alloc] init];
        [_guideLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.text = STRING.user_3rd_guide;
            temp.font = UILightFontMake(12);
            temp.textColor = UIColorMake(151, 151, 151);
            temp.textAlignment = NSTextAlignmentCenter;
        }];
        [_guideLabel sizeToFit];
    }
    return _guideLabel;
}

-(UIImageView *) headerImageView
{
    if (!_headerImageView)
    {
        _headerImageView = [UIImageView new];
        _headerImageView.image = [UIImageMake(@"myCard_userHeader") qmui_imageWithScaleToSize:CGSizeMake(90, 90)];
        _headerImageView.contentMode = UIViewContentModeCenter;
        [_headerImageView sizeToFit];
    }
    return _headerImageView;
}

-(UILabel *) nameLabel
{
    if (!_nameLabel)
    {
        _nameLabel = [[UILabel alloc] init];
        [_nameLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIMediumFontMake(16);
            temp.textColor = UIColorMake(0, 0, 0);
            temp.textAlignment = NSTextAlignmentCenter;
        }];
    }
    return  _nameLabel;
}

-(UILabel * )titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        [_titleLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIMediumFontMake(12);
            temp.textColor = UIColorMake(0, 0, 0);
            temp.textAlignment = NSTextAlignmentCenter;
        }];
    }
    return  _titleLabel;
}

-(UILabel * )jobLable
{
    if (!_jobLable)
    {
        _jobLable = [[UILabel alloc] init];
        [_jobLable setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIMediumFontMake(12);
            temp.textColor = UIColorMake(0, 0, 0);
            temp.textAlignment = NSTextAlignmentCenter;
        }];
    }
    return  _jobLable;
}

-(UIImageView *)emailImageView
{
    if (!_emailImageView)
    {
        _emailImageView = [UIImageView new];
        _emailImageView.image = UIImageMake(@"user_3rd_info_email");
        _emailImageView.contentMode = UIViewContentModeCenter;
        [_emailImageView sizeToFit];
    }
    return _emailImageView;
}


-(UILabel *) emailLabel
{
    if (!_emailLabel)
    {
        _emailLabel = [[UILabel alloc] init];
        [_emailLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(12);
            temp.textColor = UIColorMake(0, 0, 0);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
    }
    return  _emailLabel;
}

-(UIImageView *)locationImageView
{
    if (!_locationImageView)
    {
        _locationImageView = [UIImageView new];
        _locationImageView.image = UIImageMake(@"user_3rd_info_location");
        _locationImageView.contentMode = UIViewContentModeCenter;
        [_locationImageView sizeToFit];
    }
    return _locationImageView;
}

-(UILabel *) locationLabel
{
    if (!_locationLabel)
    {
        _locationLabel = [[UILabel alloc] init];
        [_locationLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(12);
            temp.textColor = UIColorMake(0, 0, 0);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
    }
    return  _locationLabel;
}

@end
